import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LENOVO
 * Date: 2024-08-08
 * Time: 14:18
 */
public class MyStack {
    public int[] stack;
    public int usedSize;

    public MyStack() {
        this.stack = new int[10];
    }
    private boolean isFull(){
        return usedSize == stack.length;
    }
    private boolean isEmpty(){
        return usedSize == 0;
    }
    private void grow(){
        this.stack = Arrays.copyOf(stack, 2 * stack.length);
    }
    public void push(int val){
        if(isFull()){
            grow();
        }
        stack[usedSize++] = val;
    }
    public int pop(){
        if(isEmpty()){
            throw new EmptyException("空栈");
        }
        return stack[--usedSize];
    }
    public int peek(){
        if(isEmpty()){
            throw new EmptyException("空栈");
        }
        return stack[usedSize -1];
    }
}
